package com.tiejun.ge.mvc.controller;

import cn.hutool.core.bean.BeanUtil;
import com.tiejun.ge.common.core.domain.R;
import com.tiejun.ge.mvc.annotation.RateLimit;
import com.tiejun.ge.mvc.common.validate.ValidationGroup;
import com.tiejun.ge.mvc.entity.bo.UserBO;
import com.tiejun.ge.mvc.entity.dto.UserDTO;
import com.tiejun.ge.mvc.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @program: springboot
 * @description: 用户1控制器
 * @author: getiejun
 * @create: 2025-07-30 23:52
 **/
@Api(value = "用户管理", tags = "用户管理")
@RestController
@RequestMapping("user")
public class UserController {

    @Resource
    private UserService userService;

    @RateLimit
    @ApiOperation("查询用户信息")
    @GetMapping
    public R<?> page(){
        return R.success(userService.page(1, 10));
    }

    @RateLimit
    @ApiOperation("查询用户详情信息")
    @PostMapping("detail")
    public R<?> detail(@Validated(value = ValidationGroup.DETAIL.class) @RequestBody UserDTO userDTO) {
        return R.success(userService.detail(userDTO.getId()));
    }

    @RateLimit
    @ApiOperation("添加用户信息v1版本")
    @PostMapping("v1")
    public R<?> age_v1(@Valid @RequestBody UserDTO userDTO) {
        userService.add(BeanUtil.copyProperties(userDTO, UserBO.class));
        return R.success();
    }

    @RateLimit
    @ApiOperation("添加用户信息v2版本")
    @PostMapping("v2")
    public R<?> age_v2(@Validated(value = ValidationGroup.ADD.class) @RequestBody UserDTO userDTO) {
        userService.add(BeanUtil.copyProperties(userDTO, UserBO.class));
        return R.success();
    }
}
